﻿@model IEnumerable<KRM.Core.tblUser>
@{
    ViewBag.Title = "Users";
    Layout = "~/Views/Shared/_Layout.cshtml";
    int page = 1;

    if (Request.QueryString["p"] != null)
    {
        page = Convert.ToInt32(Request.QueryString["p"]);

    }

    int itemPerPage = 40;
    int pagingCount = Convert.ToInt32(Math.Ceiling((Model.Count() / (float)itemPerPage)));
    var listPaging = Model.Skip((page - 1) * itemPerPage).Take(itemPerPage).ToList();
    <script src="~/js/User.js"></script>
    }

<div id="changedepartment" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="changedepartment" aria-hidden="true">
    <div class="ajax-loading"></div>
</div>

<div class="container-fluid">
    <div id="modaltoggle"></div>
    <div class="page-header">
        <form action="/users" method="get" class="margin0">
            <div class="row-fluid">
                <div class="span2">
                    @*<a style="width: 55px" class="btn btn-mini btn-refresh-board" href="/users/adduser">Add user </a>*@
                    <input type="button" class="btn btn-success w100" onclick="PopupCenter('/users/adduser', 800, 600)" value="Add User"/>
                </div>
                
                <div class="span6"></div>
                <div class="span3">
                    <input type="text" name="q" value="" placeholder="User name" class="input-block-level" />
                </div>
                <div class="span1">
                    <input type="submit" value="Search" class="btn btn-primary" style="width: 100%" />
                </div>
            </div>

        </form>
    </div>
    @if (!string.IsNullOrEmpty(ViewBag.msg) && ViewBag.msg == "success")
    {
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>Success!</strong>
        </div>
    }
    <div class="row-fluid">
        <table class="table table-hover table-bordered table-fix">
            <thead>
                <tr>
                    <th>UserID</th>
                    <th>Username</th>
                    <th>UserLogin</th>
                    <th>Email</th>
                    <th>Department</th>
                    <th>UserAuth</th>
                    @*<th>Change Department</th>*@
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in listPaging)
                {
                    var department = item.WebPermissionDepartments.FirstOrDefault();
                    <tr >
                        <td>
                            @item.UserID
                        </td>
                        <td>
                            @item.Username
                        </td>
                        <td>
                            @item.UserLogin
                        </td>
                        <td>
                            @item.MyEmail
                        </td>
                        <td>
                            @(department != null ? department.Name : "")
                        </td>
                        <td>
                            @item.UserAuth
                        </td>
                        @*<td><a data-toggle="modal" href="#changedepartment" title="Change department" onclick="changedepartment(@item.UserID)">
                                <img src="/img/AddRecord.gif" /></a>
                        </td>*@
                        <td style="text-align: center">
                            <a href="javascript:;" onclick="EditUser(@item.UserID,800,600)">Edit</a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <div class="paging">
            <a href="/users">«</a>
            <span>
                @for (int j = page - 3; j <= page + 3; j++)
                {
                    if (j > 0 && j <= pagingCount)
                    {
                        if (j == page)
                        {
                    <a href="/users?p=@j" class="page-active">@j</a>
                        }
                        else
                        {
                    <a href="/users?p=@j">@j</a>
                        }

                    }
                }
            </span>
            <a href="/users?p=@pagingCount">»</a>
        </div>
    </div>
</div>
